import React from 'react'
import sidebar from "./sidebar";
import {user} from "../request";
import {useNavigate} from 'react-router-dom'

function MyUntil(props){
    const navigate = useNavigate()
    const setNewArr = props.getNewArr
    React.useEffect(()=>{
        const mySigIn = async()=>{
            if (await localStorage.getItem('token') !== null){
                const {data:res} = await user.getUser(await localStorage.getItem('token'))
                let myUser = res.data[0]
                for (let i = 0; i < sidebar[1].list.length; i++) {
                    if (sidebar[1].list[i].live > myUser.user_live){
                        sidebar[1].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[2].list.length; i++) {
                    if (sidebar[2].list[i].live > myUser.notice_live){
                        sidebar[2].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[3].list.length; i++) {
                    if (sidebar[3].list[i].live > myUser.adve_live){
                        sidebar[3].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[4].list.length; i++) {
                    if (sidebar[4].list[i].live > myUser.coupon_live){
                        sidebar[4].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[5].list.length; i++) {
                    if (sidebar[5].list[i].live > myUser.juris_live){
                        sidebar[5].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[6].list.length; i++) {
                    if (sidebar[6].list[i].live > myUser.comm_liveto){
                        sidebar[6].list.splice(i,1)
                    }
                }
                for (let i = 0; i < sidebar[7].list.length; i++) {
                    if (sidebar[7].list[i].live > 1){
                        sidebar[7].list.splice(i,1)
                    }
                }
                if (myUser.user_live === -1){
                    sidebar.splice(1,1)
                }
                if (myUser.notice_live === -1){
                    sidebar.splice(2,1)
                }
                if (myUser.adve_live === -1){
                    sidebar.splice(3,1)
                }
                if (myUser.coupon_live === -1){
                    sidebar.splice(4,1)
                }
                if (myUser.juris_live === -1){
                    sidebar.splice(5,1)
                }
                if (myUser.comm_liveto === -1){
                    sidebar.splice(6,1)
                    sidebar.splice(7,1)
                }
                setNewArr(sidebar)
                let arr = []
                let arr1 = []
                let url = window.location.pathname.split('/')[2]
                if (url !== undefined) {
                    for (let i = 0; i < sidebar.length; i++) {
                        if (sidebar[i].list !== undefined) {
                            for (let j = 0; j < sidebar[i].list.length; j++) {
                                arr.push(sidebar[i].list[j].path)
                                if (url !== sidebar[i].list[j].path && url !== 'home'){
                                    arr1.push(sidebar[i].list[j].path)
                                }

                            }
                        }
                    }
                    if (arr.length === arr1.length){
                        // navigate('*')
                        window.top.location.replace('*')
                    }
                }
            }else {
                if (window.location.pathname !== '/' || window.location.pathname !== 'Login'){
                    window.top.location.replace('/')
                    // navigate('/')
                }
            }
        }
        mySigIn()

    },[])



    return(
        <div>

        </div>
    )
}
export default MyUntil